package com.oa.co.service.impl;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

import com.oa.co.common.R;
import com.oa.co.mapper.ExpenseAccountMapper;
import com.oa.co.pojo.Expense_account;
import com.oa.co.pojo.Overtime_application_form;
import com.oa.co.pojo.Schedule;
import com.oa.co.service.ExpenseAccountService;
import com.oa.co.service.ScheduleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author sunXuDong
 * @data 2023/5/8
 */
@Service("expenseAccountService")
public class ExpenseAccountServiceImpl implements ExpenseAccountService {
    @Autowired
    private ExpenseAccountMapper expenseAccountMapper;
    @Autowired
    private ScheduleService scheduleService;

    @Override
    public R allDate(Expense_account expense_account) {
        if (expense_account!=null){
            Integer add =   expenseAccountMapper.allDate(expense_account);
            Schedule schedule = Schedule.getInstance();
            BeanUtils.copyProperties(expense_account,schedule);
            R  r = scheduleService.add(schedule);
            if (add==1 && r.getCode()==200){
                return  R.ok();
            }
            return R.error();
        }
        return R.error();
        }

    @Override
    public R deleteDate(Expense_account expense_account) {
        if (expense_account!=null) {
            Schedule schedule = scheduleService.queryId(expense_account.getD_id());
            if (schedule.getD_code()==6){
                Integer del = scheduleService.del(expense_account.getD_id());
                Integer del1 = expenseAccountMapper.del(expense_account.getD_id());

                if (Objects.equals(del,del1)){
                    return R.ok().message("撤回成功");
                }

                return R.error();
            }else {
                return R.error().message("已在审批,撤回失败");
            }

        }

        return R.error().message("expense_account");
    }

    @Override
    public R query(String d_id) {
        List<Expense_account> list = expenseAccountMapper.query(d_id);
        System.out.println(list);
        return list !=null? R.ok().data("res",list):R.error();
    }


}
